<template>
  <div class="anime-gallery">
    <!-- 漫画轮播图部分 -->
    <div class="manga-section">
      <!-- 轮播图 -->
      <div class="manga-carousel-wrapper">
        <GlassmorphismCarousel scene="anime" />
      </div>

      <!-- 标签导航 -->
      <div class="tag-nav">
        <div class="tag-nav-inner">
          <a-tag
            v-for="tag in tags"
            :key="tag"
            :class="{ 'tag-active': selectedTag === tag }"
            @click="handleTagClick(tag)"
          >
            {{ tag }}
          </a-tag>
        </div>
      </div>
    </div>

    <div class="recommendation-header">
      <span class="title">为你推荐</span>
      <span class="subtitle">Pick你的最爱！</span>
    </div>

    <div class="gallery-container">
      <a-empty v-if="!pictures.length" description="暂无图片" />
      <PictureList v-else :dataList="pictures" :loading="loading" :showOp="false" />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { SearchOutlined } from '@ant-design/icons-vue'
import PictureList from '@/components/PictureList.vue'
import GlassmorphismCarousel from '@/components/GlassmorphismCarousel.vue'
import { listPictureVoByPageWithCacheUsingPost } from '@/api/pictureController'
import { message } from 'ant-design-vue'

const loading = ref(false)
const selectedCategory = ref<string>()
const selectedStyle = ref<string>()
const selectedTag = ref('热血')
const current = ref(1)
const pageSize = ref(12)

// 标签数据
const tags = ['热血燃向', '古风奇幻', '都市异能', '校园青春', '西幻冒险', '全部 >']

const categories = [
  { value: 'character', label: '人物' },
  { value: 'scenery', label: '场景' },
  { value: 'mecha', label: '机甲' },
  { value: 'fantasy', label: '奇幻' },
]

const styles = [
  { value: 'japanese', label: '日系' },
  { value: 'chinese', label: '国风' },
  { value: 'realistic', label: '写实' },
  { value: 'cartoon', label: '卡通' },
]

const pictures = ref<API.PictureVO[]>([])

// 获取图片列表
const loadPictures = async () => {
  loading.value = true
  try {
    const res = await listPictureVoByPageWithCacheUsingPost({
      current: current.value,
      pageSize: pageSize.value,
      category: '二次元',
      tags: selectedTag.value !== '全部 >' ? [selectedTag.value] : undefined,
      sortField: 'createTime',
      sortOrder: 'descend',
    })
    if (res.data?.code === 0 && res.data?.data) {
      pictures.value = res.data.data.records || []
    } else {
      message.error('获取图片列表失败：' + res.data?.message)
    }
  } catch (error) {
    message.error('获取图片列表失败')
  } finally {
    loading.value = false
  }
}

const handleTagClick = (tag: string) => {
  selectedTag.value = tag
  current.value = 1 // 切换标签时重置页码
  loadPictures()
}

// 页面加载时执行
onMounted(() => {
  console.log('Page mounted, loading pictures...')
  loadPictures()
})
</script>

<style scoped>
.anime-gallery {
  padding: 5px;
}

/* 漫画区域样式 */
.manga-section {
  width: 100%;
  background-color: #1a1a1a;
}

/* 轮播图样式 */
.manga-carousel-wrapper {
  width: 100%;
  padding: 0 0 5px 0;
}

.manga-carousel {
  width: 100%;
  margin: 0 auto;
}

.manga-slide {
  width: 100% !important;
  padding: 0;
  box-sizing: border-box;
  display: flex !important;
  justify-content: center;
  align-items: center;
}

.manga-card {
  position: relative;
  border-radius: 0;
  overflow: hidden;
  height: 500px;
  width: 100%;
  max-width: 100%;
  cursor: pointer;
  transition: transform 0.3s;
}

.manga-card:hover {
  transform: translateY(-5px);
}

.manga-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.manga-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  color: white;
}

.manga-title {
  font-weight: bold;
  font-size: 24px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.manga-desc {
  font-size: 16px;
  opacity: 0.8;
  margin-top: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 标签导航样式 */
.tag-nav {
  width: 100%;
  background-color: #222;
  padding: 10px 0;
  overflow-x: auto;
}

.tag-nav-inner {
  display: flex;
  justify-content: center;
  flex-wrap: nowrap;
  white-space: nowrap;
  padding: 0 20px;
}

.tag-nav::-webkit-scrollbar {
  height: 4px;
}

.tag-nav::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.tag-nav :deep(.ant-tag) {
  cursor: pointer;
  padding: 4px 12px;
  font-size: 14px;
  margin: 4px 8px;
  border: none;
  background: transparent;
  color: #faf8f8;
}

.tag-nav :deep(.ant-tag):hover {
  color: #fff;
}

.tag-nav :deep(.tag-active) {
  color: #00a1d6 !important;
  font-weight: bold;
}

/* 页面内容样式 */
.recommendation-header {
  margin-top: 50px;
  text-align: left;
  margin-bottom: 42px;
  margin-left: 34px;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.recommendation-header .title {
  font-size: 36px;
  color: #000;
  font-weight: normal;
  line-height: 1;
}

.recommendation-header .subtitle {
  color: #b4b4b4;
  font-size: 16px;
  font-weight: normal;
  margin-top: 4px;
}

.filter-section {
  margin: 0 24px 24px;
  display: flex;
  justify-content: center;
}

.gallery-container {
  margin: 0 24px;
  min-height: 400px;
}

/* 轮播图导航点样式 */
:deep(.ant-carousel .slick-dots) {
  bottom: -25px;
}

:deep(.ant-carousel .slick-dots li button) {
  background: rgba(255, 255, 255, 0.4);
}

:deep(.ant-carousel .slick-dots li.slick-active button) {
  background: #00a1d6;
}

/* 修复轮播图宽度问题 */
:deep(.ant-carousel .slick-slide) {
  pointer-events: none;
}

:deep(.ant-carousel .slick-slide > div) {
  width: 100%;
}

:deep(.ant-carousel) {
  width: 100%;
}

:deep(.slick-list) {
  width: 100%;
}

:deep(.slick-track) {
  width: 100%;
}

/* 响应式布局 */
@media (max-width: 768px) {
  .manga-card {
    height: 300px;
  }

  .manga-title {
    font-size: 20px;
  }

  .manga-desc {
    font-size: 14px;
  }
}

@media (max-width: 576px) {
  .manga-card {
    height: 240px;
  }

  .manga-title {
    font-size: 18px;
  }

  .manga-desc {
    font-size: 12px;
  }
}
</style>
